<!--
 * @Description: 生产处客户管理
 * @Author: wangwangwang
 * @Date: 2020-08-17 15:52:58
 * @LastEditors: wangwangwang
 * @LastEditTime: 2020-12-09 11:56:34
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">客户名称</span>
                <el-input v-model="tableParam.name" style="width: 150px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">联系电话</span>
                <el-input v-model="tableParam.linkman" style="width: 20%;max-width: 150px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="addFromDate('添加客户'),disabledType=false">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加客户
              </el-button>
            </div>
            <div>
              <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                <el-link :underline="false">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_filtrate"></i>
                  </span>
                  筛选
                </el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item, index) in table" :key="index">
                    <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>

          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark">
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                  <template slot-scope="scope">
                    <div v-if="item.label == '历史合作记录'">
                      <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" size="mini" class="bottom_one" @click="changeEngineerings(scope.row)">查看</el-button>
                    </div>
                    <div v-else-if="item.label == '操作'">
                      <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='XIUGAI'))!==-1" size="mini" class="bottom_one" @click="updateFromDate(scope.row, '修改'),principalName = scope.row.createUserName,disabledType=false">修改</el-button>
                      <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='SHANCHU'))!==-1" size="small" class="bottom_two" @click="Delete(scope.row)">
                        删除
                      </el-button>
                    </div>
                    <span v-else>{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
          <div class="card_bottom">
            <div class="card_bottom_left">
              <div class="top_page_totle">总共{{ total }}条</div>
              <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
            </div>
            <div>
              <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="580px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :inline="true" :model="fromDate" label-width="110px" :disabled="disabledType" hide-required-asterisk :rules="rules">
          <el-form-item prop="name" :rules="[{required: true,message: '请输入客户名称',trigger: 'change',}]">
            <span slot="label" style="color:  #FF0000;">客户名称</span>
            <el-input v-model="fromDate.name" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="phone">
            <span slot="label" style="color:  #FF0000;">联系电话</span>
            <el-input v-model="fromDate.phone" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item prop="address" :rules="[{required: true,message: '请输入联系地址',trigger: 'change',}]">
            <span slot="label" style="color:  #FF0000;">联系地址</span>
            <el-input v-model="fromDate.address" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">备注信息</span>
            <el-input v-model="fromDate.remark" :rows="5" resize="none" style="width: 320px;" type="textarea" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button v-show="disabledType" class="bottom_all_two" @click="resetFromDate">关 闭</el-button>
        <el-button v-show="!disabledType" class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button v-show="!disabledType" class="bottom_all" style="margin-left: 24px;" @click="submit()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 合作工程 -->
    <el-dialog v-dialogDrag :visible.sync="cooperationDialog" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">合作项目</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="cooperationlist" tooltip-effect="dark">
          <el-table-column label="工程编号" align="center" prop="code"></el-table-column>
          <el-table-column label="工程名称" align="center" prop="name"></el-table-column>
          <el-table-column label="工程地址" align="center" prop="place"></el-table-column>
          <el-table-column label="供应日期" align="center" prop='startTime' width="170"></el-table-column>
          <el-table-column label="累计销量" align="center" prop="cumulativeSales"></el-table-column>
          <el-table-column label="累计产值" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cumulativeOutput" placeholder="请输入数字" style="width:100%;" class="FZY" @blur="updateRecordFun(scope.row)">
                <template slot="append">元</template>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="累计回款" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cumulativePayback" class="FZY" style="width:100%;" placeholder="请输入数字" @blur="updateRecordFun(scope.row)">
                <template slot="append">元</template>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.proRemark" style="width:100%;" placeholder="请输入" @blur="updateRecordFun(scope.row)">
              </el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="cooperationDialog = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  saveOrUpdate,
  queryEngineering,
  updateRecord,
} from "@/api/internetSales/customerProduction.js";
import {
  post
} from '@/api/table.js';
export default {
  mixins: [mixin],
  data() {
    var landlinePhone = (rule, value, callback) => {
      if (!this.$regExp.landlinePhoneReg(value)) {
        return callback(new Error('电话格式错误！'));
      } else {
        callback();
      }
    };
    return {
      look5TypeName: '',
      ByTypeData: [],
      type: '',
      look5Type: false,
      startTimDateEndTimDate: [],
      tableParamType: false,
      disabledType: false,
      principalName: "",
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      saveOrUpdate: saveOrUpdate,
      loading: false,
      /*表格数据*/
      table: [
        {
          label: "客户名称",
          width: "",
          prop: "name",
          status: true,
        },
        {
          label: "联系电话",
          width: "",
          prop: "phone",
          status: true,
        },
        {
          label: "联系地址",
          width: "",
          prop: "address",
          status: true,
        },
        {
          label: "备注信息",
          width: "",
          prop: "remark",
          status: true,
        },
        {
          label: "历史合作记录",
          width: "",
          prop: "120",
          status: true,
        },
        {
          label: "操作",
          width: "160",
          prop: "",
          status: true,
        },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      fromDate: {
        name: "",
        phone: "",
        address: "",
        remark: "",
      },
      rules: {
        phone: [{ validator: landlinePhone, trigger: 'change' }]
      },
      companyNatureIdlist: [],
      cooperationClassIdlist: [],
      clientTypeIdlist: [],
      exportDialog: false,
      cooperationDialog: false,
      cooperationlist: [],
    };
  },
  async created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, name: "", phone: "" };
    this.gettableData();
  },
  methods: {
    /*合作项目*/
    changeEngineerings(low) {
      queryEngineering({ id: low.id }).then((res) => {
        this.cooperationlist = res.data;
        console.log(res.data);
        this.cooperationDialog = true;
      });
    },
    init() {
      /*重置数据*/
      this.tableParam.name = "";
      this.tableParam.linkman = "";
      this.gettableData();
    },
    submit() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          _this.submitFromDate();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    Delete(row) {
      this.$confirm('此操作将删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'bottom_all_two',
        confirmButtonClass: 'bottom_all',
        type: 'warning'
      }).then(() => {
        let json = {
          id: row.id,
          status: 0
        }
        post(this.saveOrUpdate, json).then((res) => {
          this.loading = false;
          this.submitLoading = false;
          if (res.code === 1001) {
            this.$message({
              message: '删除成功',
              type: "success",
            });
            this.gettableData()
          }
        });
      })
    },
    updateRecordFun(row) {
      updateRecord(row).then((res) => {
        if (res.code == 1001) {
          this.$message({
            message: '修改成功',
            type: "success",
          });
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.table_top {
  color: #008000;
}
.table_top:hover {
  color: #008000 !important;
  opacity: 0.8;
}
.el-input,
.el-select {
  width: 320px;
}
.table_link {
  margin-left: 10px;
  color: $bg_color;
}
.table_link:hover {
  opacity: 0.8;
}
.dialoginfo-title {
  > div {
    cursor: pointer;
  }
  height: 48px;
  display: flex;
  background: linear-gradient(
    180deg,
    rgba(250, 252, 255, 1) 0%,
    rgba(245, 247, 250, 1) 100%
  );
  .none {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(100% / 2);
    border-bottom: 1px solid #e1e5ed;
    > div {
      line-height: 48px;
      border-bottom: 1px rgba(0, 0, 0, 0) solid;
    }
  }
  .active {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(100% / 2);
    border: 1px solid #e1e5ed;
    border-bottom: 0;
    background: #ffffff;
    > div {
      color: $bg_color;
      line-height: 48px;
      border-bottom: 1px $bg_color solid;
    }
  }
}
.no-data {
  text-align: center;
}
.FZY ::v-deep .el-input-group__append {
  padding: 0px 8px;
}
</style>